package com.esfak47.mediafetcher.app.event;

import com.esfak47.mediafetcher.core.event.Event;
import com.esfak47.mediafetcher.core.event.EventGroupEnum;
import com.google.common.eventbus.Subscribe;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @author tony
 * @date 2018/5/21
 */
public class SystemEventListener {
    private final ConfigurableApplicationContext context;

    public SystemEventListener(ConfigurableApplicationContext context) {this.context = context;}

    @Subscribe
    public void onEvent(Event event) {
        System.out.println(event);
        if (event.getGroup() == EventGroupEnum.SYSTEM) {
            switch (event.getSubject()) {
                case "end":
                    context.close();
                    System.exit(0);
                    break;
                default:
                    break;
            }
        }
    }
}
